<template>
	<view class="container">
<!-- 		<view class="w-100" style="height: 360rpx;">
			<image src="https://prod-mall-cos-1252929494.cos.ap-guangzhou.myqcloud.com/fbd8ec7bc19541d1a692870bff4485b2.png" class="w-100" mode="widthFix"></image>
		</view> -->
		<swiper class="banner-swiper" :indicator-dots="true" :autoplay="true" :interval="3000" :duration="1000">
			<swiper-item class="swier-item" v-for="(ad,index) in ads" :key="index">
				<image :src="ad.AdsImg" class="w-100" mode="widthFix"></image>
			</swiper-item>

		</swiper>

		<view class="content-section">
			<!-- 新品推荐 begin -->
			<view class="new-arrivals">
				<view class="section-header">
					<view class="title">新 品 推 荐</view>
					<view class="subtitle">NEW ARRIVALS</view>
				</view>
				<view class="section-body">
					<image v-for="(b,index) in banners" :key="index" :src="b.AdsImg" mode="widthFix"></image>
				</view>
			</view>
			<!-- 新品推荐 end -->
			<view class="section-header">
				<view class="title">猜 你 喜 欢</view>
				<view class="subtitle">YOU MAY ALSO LIKE</view>
			</view>
		</view>
		
		<!-- 猜你喜欢 begin -->
		<view class="you-may-also-like">
			<view class="product" v-for="(product, index) in mart" :key="index" open-type="navigate" hover-class="none" @click="togoPage(product)">
				<image :src="product.name_image" mode="widthFix"></image>
				<view class="info">
					<view class="desc">
						<view class="title">{{ product.name }}</view>
						<view class="sub">{{ product.id }}人已购买</view>
					</view>
					<view class="extra">
						<view class="price">￥{{ product.price }}</view>
						<view class="action">
							<image src="/static/images/common/round_add_normal.png"></image>
						</view>
					</view>
				</view>
			</view>
		</view>
		<!-- 猜你喜欢 end -->
		
		<nomore text="已经到底了,去其他页面逛逛吧" visible></nomore>
	</view>
</template>

<script>
	import nomore from '@/components/nomore/nomore.vue'
	
	export default {
		components: {
			nomore
		},
		data() {
			return {
				categories:[],
				ads:[],
				banners:[],
				mart: []
			}
		},
		async onLoad() {
			this.getAds();
			await this.getCategories(5);
		},
		methods:{		
			togoPage(pdt){
				let product=JSON.stringify(pdt);
				uni.navigateTo({
					url:`/pages/mart/detail?product=${product}`
				})
			},
			//获取分类数据
			getCategories(coid) {
				let that = this;
				let cateOp = {
					url: `api/Lx_Self_Categories/UI_GetCategories?coid=${coid}`,
					data: {}
				}

				this.$request.Post(cateOp, (ret) => {
					if (ret.data.length > 0) {
						that.categories = ret.data;
						that.categories.map(e => {
							e.products.map(n => {
								n.images.map(img => {
									img.url = that.$request.setImgUrl(img.url, "123");
									return img;
								})
								n.name_image = that.$request.setImgUrl(n.name_image, "123");
								
								//没有配置ppt图片的使用主图
								if (n.images.length == 0) {
									n.images.push({
										id: 0,
										url: n.name_image
									});
								}
								
								return n;
							});
						
							return e;
						});
						
						if(that.categories.length>0){
							that.mart=that.categories[0].products;
						}
						
					}
				});
			},

			//获取广告数据
			getAds() {
				let that = this;
				let whe=[];
				whe.push({
					"name": "AdsType",
					"value": "3,4",
					"displayType": 'checkbox'
				});
				let cateOp = {
					url: "api/Lx_Self_Ads/UI_GetPageData",
					data: {
						"page": 1,
						"rows": 20,
						"sort": "CreateDate",
						"order": "desc",
						"wheres": JSON.stringify(whe)
					}
				}
			
				this.$request.Post(cateOp, (ret) => {
					if (ret.rows.length > 0) {
						let data = ret.rows;
						data.map(n => {
							n.AdsImg = that.$request.setImgUrl(n.AdsImg,"ttt");
							return n;
						});
						that.ads=data.filter(e=>{
							return e.AdsType==3
						});
						that.banners=data.filter(e=>{
							return e.AdsType==4
						})
					}
				});
			},
		}
	}
</script>

<style lang="scss">
	page {
		height: auto;
		
		/* #ifdef H5 */
		min-height: 100%;
		/* #endif */
	}
	
	.banner-swiper {
		height: 400rpx;
		
		.swier-item {
			image {
				height: 100%;
			}
		}
	}
	
	.banner-section {
		display: flex;
		background-color: #FFFFFF;
		
		image {
			width: 375rpx;
		}
	}
	
	.section-header {
		display: flex;
		align-items: baseline;
		padding: 20rpx 0;
		.title {
			font-family: 'wenyue';
			font-size: 44rpx;
			margin-right: 20rpx;
		}
		
		.subtitle {
			font-family: 'neutra';
			font-size: $font-size-sm;
			color: $text-color-assist;
		}
	}
	
	.content-section {
		background-color: #FFFFFF;
		padding: 0 30rpx;
	}
	
	.new-arrivals {
		margin-bottom: 20rpx;
		.section-body {
			display: flex;
			flex-direction: column;
			
			image {
				width: 100%;
				margin-bottom: 10rpx;
			}
		}
	}
	
	.you-may-also-like {
		padding: 20rpx 30rpx;
		display: flex;
		flex-wrap: wrap;
		justify-content: space-between;
		
		.product {
			background-color: #FFFFFF;
			width: 335rpx;
			display: flex;
			flex-direction: column;
			border-radius: $border-radius-lg;
			margin-bottom: 20rpx;
			
			image {
				width: 100%;
				border-radius: $border-radius-lg $border-radius-lg 0 0;
			}
			
			.info {
				padding: 20rpx;
				display: flex;
				flex-direction: column;
				overflow: hidden;
				
				.desc {
					display: flex;
					flex-direction: column;
					
					.title {
						font-size: $font-size-lg;
						overflow: hidden;
						text-overflow: ellipsis;
						white-space: nowrap;
						margin-bottom: 14rpx;
					}
					
					.sub {
						font-size: $font-size-sm;
						color: $text-color-assist;
					}
				}
				
				.extra {
					margin-top: 20rpx;
					display: flex;
					align-items: center;
					justify-content: space-between;
					
					.price {
						color: $color-primary;
						font-size: $font-size-lg;
						font-weight: 500 !important;
					}
					
					.action {
						image {
							width: 40rpx;
							height: 40rpx;
						}
					}
				}
			}
		}
	}
</style>
